//
//  ShowTableViewCell.m
//  NineGroupProject
//
//  Created by dllo on 15/12/28.
//  Copyright © 2015年 lushan. All rights reserved.
//

#import "ShowTableViewCell.h"
#import "ShowCollectionViewCell.h"
@interface ShowTableViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate>

@end

@implementation ShowTableViewCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}


-(void)createSubViews{
    self.label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 350, 500)];
    self.label.numberOfLines = 0;
    [self.contentView addSubview:self.label];
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    
    flowLayout.estimatedItemSize = CGSizeMake(10, 120 *HEI);
    flowLayout.minimumInteritemSpacing = 5;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 5, 0, 0);
    self.collectionV = [[UICollectionView alloc] initWithFrame:CGRectMake(10 * WID, self.label.frame.origin.y + 10 * HEI, WIDTH - 10 * WID, 140 * HEI) collectionViewLayout:flowLayout];
    [self.contentView addSubview:self.collectionV];
    
    [self.collectionV registerClass:[ShowCollectionViewCell class] forCellWithReuseIdentifier:@"ShowCollectionViewCell"];
    self.collectionV.delegate = self;
    self.collectionV.dataSource = self;
    self.collectionV.backgroundColor = [UIColor whiteColor];
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return self.travelDetail.notes.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdenrifier = @"ShowCollectionViewCell";
    ShowCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdenrifier forIndexPath:indexPath];
    cell.notes = [self.travelDetail.notes objectAtIndex:indexPath.row];
    cell.backgroundColor = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1.0];
    
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    Notes *notes = [self.travelDetail.notes objectAtIndex:indexPath.row];
    return CGSizeMake(notes.width * 120 * HEI / notes.height, 120 * HEI);
}



-(void)setTravelDetail:(TravelDetailModel *)travelDetail{
    _travelDetail = travelDetail;
    
    self.label.text = travelDetail.placeDescription;
    
    self.label.frame = CGRectMake(10 * WID, 10 * WID, WIDTH - 20 * WID, travelDetail.height);
    
    self.collectionV.frame = CGRectMake(10 * WID, self.label.frame.origin.y + 10 * HEI + travelDetail.height, WIDTH - 10 * WID, 140);
    [self.collectionV reloadData];
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
